function EEG = cvc_dipfit(EEG)
% DIPFIT
%
%  Synopsis
%  ========
%
%  EEG = cvc_dipfit(EEG)
%
%  -- Author: Mads Dyrholm --
%     Center for Visual Cognition, University of Copenhagen.
%     April 2011
%
%  Purpose
%  =======
%  
%  Fit dipoles.

fitcomps = 1:size(EEG.icaact,1);

EEGchans = eeg_chantype(EEG.chanlocs, 'EEG' );

path22=(which('dipfitdefs.m'));

EEG = pop_dipfit_settings( EEG, 'hdmfile', ... 
			   fullfile(path22,'standard_BESA','standard_BESA.mat'), ...
			   'coordformat', 'Spherical', 'mrifile', ...
			   fullfile(path22,'standard_BESA','avg152t1.mat'), ...
			   'chanfile', ...
			   fullfile(path22,'standard_BESA','standard-10-5-cap385.elp'), ...
			   'coord_transform',[0 0 0 0 0 0 85.3498 85.3498 85.3498] , 'chansel', EEGchans );
EEG = pop_multifit(EEG, fitcomps, 'threshold',40, 'plotopt',{ 'normlen', 'on'});
%pop_dipplot( EEG,talcomps, 'mri', '/home/mads/professor/Copenhagen/lib/eeglab8_0_3_1b/plugins/dipfit2.2/standard_BESA/avg152t1.mat', 'normlen', 'on');
